<template>
  <div class="main">
    <el-container class="main-content">
      <el-header>
        <nav-header/>
      </el-header>
      <el-container class="content">
        <el-aside :width="isCollapse ? '60px' : '210px'">
          <nav-menu @foldChange="foldChange" />
        </el-aside>
        <el-main>
          <breadcrumb :breads="breads"></breadcrumb>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang='ts'>
import { defineComponent, ref, computed } from "vue";
import NavHeader from '@/components/nav-header'
import NavMenu from '@/components/nav-menu'
import Breadcrumb from '@/base-ui/breadcrumb'

import { useStore } from '@/store'
import { useRoute } from 'vue-router'
import { pathMapBreakcrumbs } from '@/utils/mapRoutes'

export default defineComponent({
  components: {
    NavHeader,
    NavMenu,
    Breadcrumb
  },
  setup() {
    const isCollapse = ref(false)

    const breads = computed(() => {
      const route = useRoute()
      const currentPath = route.path
      const store = useStore()
      const userMenus = store.state.login.roleMenus
      return pathMapBreakcrumbs(userMenus, currentPath)
    })

    const foldChange = (val: boolean) => {
      isCollapse.value = val
    }

    return {
      isCollapse,
      breads,
      foldChange
    }
  }
});
</script>

<style scoped lang='less'>
.main {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  .el-header {
    height: 48px !important;
    border-bottom: 1px solid #ccc;

    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .content {
    height: calc(100vh - 48px);
    .el-aside {
      overflow-y: auto;
      overflow-x: hidden;
      text-align: left;
    }
  }
}

.el-main {
  background-color: #f0f2f5;
}
</style>
